<template>
  <HomePanel ref="target" title="新鲜好物" subTitle="新鲜出炉 品质靠谱">
    <template #right>
      <XtxMore/>
    </template>
    <GoodsList :list="newList"/>
  </HomePanel>
</template>
<script>
import HomePanel from './home-panel.vue'
import { findNew } from '@/api/home'
import { ref } from 'vue'
import GoodsList from './goods-list.vue'
import { useObserver } from '@/hook'
export default {
  name: 'HomeNew',
  components: {
    HomePanel,
    GoodsList
  },
  setup () {
    // 商品列表
    const newList = ref([])

    // 获取商品列表的函数
    const getNewList = async () => {
      const res = await findNew()
      // console.log(res)
      newList.value = res.result
    }

    // 调用
    // onMounted(() => {
    //   getNewList()
    // })
    const { target } = useObserver(getNewList)
    return { newList, target }
  }
}
</script>
<style scoped lang="less">
</style>
